
from PyQt6 import QtCore, QtGui, QtWidgets
from PyQt6.QtWidgets import QWidget,QApplication,QMessageBox
import sys
import main_admin
import main_teacher
import create_tables


class Ui_Form(QWidget):
    def __init__(self):
        super(Ui_Form,self).__init__()
        self.setupUi(self)
        create_tables.student_info_init()
        create_tables.log_init()

    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(407, 336)
        self.formLayoutWidget = QtWidgets.QWidget(parent=Form)
        self.formLayoutWidget.setGeometry(QtCore.QRect(80, 140, 231, 61))
        self.formLayoutWidget.setObjectName("formLayoutWidget")
        self.formLayout = QtWidgets.QFormLayout(self.formLayoutWidget)
        self.formLayout.setContentsMargins(10, 10, 10, 0)
        self.formLayout.setSpacing(25)
        self.formLayout.setObjectName("formLayout")
        self.label = QtWidgets.QLabel(parent=self.formLayoutWidget)
        self.label.setObjectName("label")
        self.formLayout.setWidget(0, QtWidgets.QFormLayout.ItemRole.LabelRole, self.label)
        self.username_input = QtWidgets.QLineEdit(parent=self.formLayoutWidget)
        self.username_input.setAutoFillBackground(False)
        self.username_input.setText("")
        self.username_input.setEchoMode(QtWidgets.QLineEdit.EchoMode.Normal)
        self.username_input.setClearButtonEnabled(False)
        self.username_input.setObjectName("username_input")
        self.formLayout.setWidget(0, QtWidgets.QFormLayout.ItemRole.FieldRole, self.username_input)
        self.login_button = QtWidgets.QPushButton(parent=Form)
        self.login_button.setGeometry(QtCore.QRect(80, 210, 81, 24))
        self.login_button.setObjectName("login_button")
        # 登录按钮绑定点击事件
        self.login_button.clicked.connect(self.login)

        self.label_2 = QtWidgets.QLabel(parent=Form)
        self.label_2.setGeometry(QtCore.QRect(90, 80, 211, 31))
        font = QtGui.QFont()
        font.setPointSize(18)
        self.label_2.setFont(font)
        self.label_2.setObjectName("label_2")
        self.reset_button = QtWidgets.QPushButton(parent=Form)
        self.reset_button.setGeometry(QtCore.QRect(230, 210, 81, 24))
        self.reset_button.setObjectName("reset_button")
        ## 重置按钮绑定点击事件
        self.reset_button.clicked.connect(self.resetForm)

        self.retranslateUi(Form)
        QtCore.QMetaObject.connectSlotsByName(Form)

    def retranslateUi(self, Form):
        _translate = QtCore.QCoreApplication.translate
        Form.setWindowTitle(_translate("Form", "管理员登录"))
        self.label.setText(_translate("Form", "账号："))
        self.username_input.setPlaceholderText(_translate("Form", "请登录账号"))
        self.login_button.setText(_translate("Form", "确定"))
        self.label_2.setText(_translate("Form", "学生宿舍分配系统"))
        self.reset_button.setText(_translate("Form", "重置"))


    def resetForm(self):
        self.username_input.setText("")

    def login(self):

        userName = self.username_input.text()

        if userName.strip() == "" :
            QMessageBox.warning(None, '系统提示', '用户名或者密码不能为空！')
        elif userName.strip() == "1000" :
            self.m=main_teacher.Ui_MainWindow_teacher()
            self.m.show()
            self.hide()
            
        elif userName.strip() == "2000" :
          
            self.m=main_admin.Ui_MainWindow_admin()
            self.m.show()
            self.hide()

        else:
            QMessageBox.warning(None, '系统提示', '用户名或者密码输入错误！')

if __name__ == '__main__':
    app = QApplication(sys.argv)

    ui = Ui_Form()
    ui.show()

    sys.exit(app.exec())
